﻿using System.Runtime.InteropServices;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;

namespace System.Buffers
{
    internal class UnsafeImageMemoryManager<TPixel> : MemoryManager<byte> where TPixel : struct, IPixel<TPixel>
    {
        private readonly Image<TPixel> _image;

        public UnsafeImageMemoryManager(Image<TPixel> image)
        {
            _image = image;
        }

        public override Span<byte> GetSpan()
        {
            return MemoryMarshal.Cast<TPixel, byte>(_image.GetPixelSpan());
        }

        public override MemoryHandle Pin(int elementIndex = 0)
        {
            throw new NotSupportedException();
        }

        public override void Unpin()
        {
            throw new NotSupportedException();
        }

        protected override void Dispose(bool disposing)
        {
        }
    }
}
